package vn.edu.uit.hotelbooking.JsonParse;

import java.util.ArrayList;

import org.json.JSONArray;

import vn.edu.uit.hotelbooking.model.Room;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class RoomListParser {
    private static final String LOG_TAG= "RoomListParser";
    private static Gson gson = new Gson();
    
    /**
     * The method to get a rooms arraylist from JSON object
     * @param jObject the JSON object
     * @return If success, return a room arraylist. If fail, return null.
     */
    public static ArrayList<Room> getRoomListFromJson(JSONArray jArray) {
        ArrayList<Room> arrlistRoom = new ArrayList<Room>();
        try {
            arrlistRoom = gson.fromJson(jArray.toString(), new TypeToken<ArrayList<Room>>(){}.getType());
            return arrlistRoom;
        } catch (Exception e) {
            // TODO: handle exception
            Log.e(LOG_TAG, e.getMessage());
        }
        return null;
    }   
}
